<?php
declare (strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Cache;

class AdNumber extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('an')
            ->setDescription('the an command');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        $output->writeln('模拟假访问人数数据');

        //白天
        $day_a = 1;
        $day_b = 8;

        //晚上
        $night_a = 10;
        $night_b = 30;

        $start = time();
        // 1分钟结束一次
        $end = $start + 60;

        $g = date('G', $start);
        if ($g >= 8 && $g <= 11) {
            $a = $day_a;
            $b = $day_b;
        } else {
            $a = $night_a;
            $b = $night_b;
        }

        $key = 'adnumber';

        while (time() <= $end) {

            $adnumber = Cache::get($key, 2384770);

            $adnumber += 1;

            Cache::set($key, $adnumber);

            $rand = mt_rand($a, $b);

            sleep($rand);
        }

        $output->writeln('模拟假访问人数数据结束');
    }

}
